package com.mybatis.plus.join.column;

import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.mybatis.plus.join.ColumnData;
import com.mybatis.plus.join.SFuncUtils;
import lombok.Data;

@Data
public class TableColumn<T> implements Column {

    private String columnName;
    private String asName;

    public TableColumn(String columnName) {
        this.columnName = columnName;
    }

    public TableColumn(SFunction<T, ?> columnFunction) {
        this.columnName = SFuncUtils.getColumnNameWithTable(columnFunction);
    }

    @Override
    public String selectColumn() {
        if (asName == null || "".equals(asName.trim())) {
            return columnName;
        }
        return columnName + " AS " + asName;
    }

    @Override
    public void fillData(ColumnData columnData) {

    }

    @Override
    public void setAsName(String asName) {
        this.asName = asName;
    }
}
